/*
 * (C) Copyright 2024 Quaming
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <asm/io.h>
#include <asm-generic/gpio.h>
#include "util_flash.h"


struct gpio_config {
	uint32_t ngpio;
	bool     active_low;
} Config = {
	.ngpio = 16, // GPIO2_0
	.active_low = 0,
};

static int flashing_fw_requested_by_gpio(void)
{
	int val;

	val = gpio_direction_input(Config.ngpio);
	if (val)
		return 0;

	val =gpio_get_value(Config.ngpio);

	return val < 0 ? 0 : (val == Config.active_low);
}

/*
 * Returns True if a firmware update is requested
 */
int flashing_fw_requested(void)
{
	return flashing_fw_requested_by_gpio();
}
